package day11Exer;


import java.util.Calendar;
import java.util.Date;

/*
* 判断当前的Date是星期几
* */
public class Demo3 {

    public static void main(String[] args) {
        System.out.println(getWeek(new Date()));
    }

    public static String getWeek(Date date){
        //创建Calendar对象
        Calendar calendar = Calendar.getInstance();

        //设置指定日期的Calendar对象
        calendar.setTime(date);

        //当week为1时时周天
        int week = calendar.get(Calendar.DAY_OF_WEEK);

        switch (week){
            case 1:
                return "周天";
            case 2:
                return "周一";
            case 3:
                return "周二";
            case 4:
                return "周三";
            case 5:
                return "周四";
            case 6:
                return "周五";
            case 7:
                return "周六";
        }

        return "错误";
    }
}
